<script>
	import Vue from 'vue'
	import { getToken } from '@/utils/auth'
	
	export default {
		onLaunch: function() {
			console.log('App Launch')

			uni.getSystemInfo({
				success: (res) => {
					this.initSize(res)
				}
			})

			// #ifdef APP-PLUS
			var info = plus.push.getClientInfo()
			console.log(JSON.stringify(info))

			/* 5+  push 消息推送 ps:使用:H5+的方式监听，实现推送 */
			// 监听点击消息事件
			plus.push.addEventListener('click', function(message) {
				plus.nativeUI.toast('push click')
				console.log('监听点击通知栏', message)
				console.log('监听点击通知栏:' + JSON.stringify(message))
				console.log(message.payload)
				console.log(JSON.stringify(message))
			}, false)

			// 监听在线消息事件
			plus.push.addEventListener('receive', function(message) {
				plus.nativeUI.toast('push receive')
				console.log('recevice:' + JSON.stringify(message))
			}, false)
			// #endif

			this.initData()
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			// 初始化数据
			initData() {
				let token = getToken()
				if (token) this.$store.dispatch('getUserInfo')
			},
			// 初始化设备尺寸
			initSize(res) {
				const systemInfo = res
				let navigationBarHeight
				let custom = {}
				// #ifndef MP
				custom = {height: 36,width: 88}
				navigationBarHeight = 44
				// #endif
				// #ifdef MP-WEIXIN
				custom = wx.getMenuButtonBoundingClientRect()
				navigationBarHeight = custom.bottom + custom.top - e.statusBarHeight * 2
				// #endif	
				systemInfo.custom = custom
				systemInfo.navigationBarHeight = navigationBarHeight
				Vue.prototype.$systemInfo = systemInfo
			}
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import url("./common/css/index.css");
	@import url("./common/css/iconfont.css");
	page {
		background-color: $page-bg-color;
	}
	/* 图片载入替代方案 */
	.image-wrapper {
		font-size: 0;
		background: #f3f3f3;
		border-radius: 4px;
	
		image {
			width: 100%;
			height: 100%;
			transition: 0.6s;
			opacity: 0;
	
			&.loaded {
				opacity: 1;
			}
		}
	}
	.lazyload{
		position: relative;
		
		&.lazypic{
			&:after{
				content: '';
				position: absolute;
				left: 0;
				top: 0;
				width: 100%;
				height: 100%;
				background-image: url();
				background-size: 100% 100%;
				opacity: 0.3;
			}
		}
		image{
			position: relative;
			z-index: 1;
			opacity: 0;
		}
		&.loaded image{
			transition: .7s;
			opacity: 1 !important;
		}
	}
	::-webkit-scrollbar {
		display:none;
		width:0;
		height:0;
		color:transparent;
	}
</style>
